// SetMesurement.cpp : implementation file
//

#include "stdafx.h"
#include "Virtual Pole.h"
#include "SetMesurement.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSetMesurement dialog

CSetMesurement::CSetMesurement(CWnd* pParent /*=NULL*/)
	: CDialog(CSetMesurement::IDD, pParent) {
	//{{AFX_DATA_INIT(CSetMesurement)
	m_dMesurments_MM_X = 1.0;
	m_dMesurments_Pixel_X = 1.0;
	m_dMesurments_MM_Y = 1.0;
	m_dMesurments_Pixel_Y = 1.0;
	m_dMesurments_Angle = 90.0;
	//}}AFX_DATA_INIT
}

void CSetMesurement::DoDataExchange(CDataExchange* pDX){
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetMesurement)
	DDX_Text(pDX, IDC_MESURMENTS_EDIT_MM_X, m_dMesurments_MM_X);
	DDV_MinMaxDouble(pDX, m_dMesurments_MM_X, 1., 10000.);
	DDX_Text(pDX, IDC_MESURMENTS_EDIT_PIXELS_X, m_dMesurments_Pixel_X);
	DDV_MinMaxDouble(pDX, m_dMesurments_Pixel_X, 1., 10000.);
	DDX_Check(pDX, IDC_MESURMENTS_CHECK_MM, m_bMesureMM);
	DDX_Text(pDX, IDC_MESURMENTS_EDIT_MM_Y, m_dMesurments_MM_Y);
	DDV_MinMaxDouble(pDX, m_dMesurments_MM_Y, 1., 10000.);
	DDX_Text(pDX, IDC_MESURMENTS_EDIT_PIXELS_Y, m_dMesurments_Pixel_Y);
	DDV_MinMaxDouble(pDX, m_dMesurments_Pixel_Y, 1., 10000.);
	DDX_Text(pDX, IDC_MESURMENTS_EDIT_ANGLE, m_dMesurments_Angle);
	DDV_MinMaxDouble(pDX, m_dMesurments_Angle, -90., 90.);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSetMesurement, CDialog)
	//{{AFX_MSG_MAP(CSetMesurement)
	ON_BN_CLICKED(IDC_MESURMENTS_BTN_X, OnMesurmentsBtn_X)
	ON_EN_CHANGE(IDC_MESURMENTS_EDIT_PIXELS, OnChangeMesurmentsEditPixels)
	ON_BN_CLICKED(IDC_MESURMENTS_BTN_Y, OnMesurmentsBtn_Y)
	ON_BN_CLICKED(IDC_MESURMENTS_BTN_ANGLE, OnMesurmentsBtn_Angle)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetMesurement message handlers

void CSetMesurement::OnMesurmentsBtn_X() {
	m_iMesureMode = 1;
	OnCancel();
}

int CSetMesurement::DoModal() {
	return CDialog::DoModal();
}

void CSetMesurement::OnOK()  {
	CDialog::OnOK();
	m_dpConversationFactor.x = (double)m_dMesurments_MM_X / (double)m_dMesurments_Pixel_X;
	m_dpConversationFactor.y = (double)m_dMesurments_MM_Y / (double)m_dMesurments_Pixel_Y;
	m_iMesureMode = 0;
}

void CSetMesurement::OnChangeMesurmentsEditPixels() {
	m_iMesureMode = 0;
}

BOOL CSetMesurement::OnInitDialog() {
	CDialog::OnInitDialog();
	
	UpdateData(false);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSetMesurement::OnMesurmentsBtn_Y() {
	m_iMesureMode = 2;
	OnCancel();
}

void CSetMesurement::OnMesurmentsBtn_Angle() {
	m_iMesureMode = 3;
	OnCancel();
}
